#include <iostream>

#include "linked_list.h"
using namespace std;
ListNode* Init() {
  ListNode* node1 = new ListNode(1);
  ListNode* node2 = new ListNode(2);
  ListNode* node3 = new ListNode(3);
  ListNode* node4 = new ListNode(4);
  ListNode* node5 = new ListNode(5);
  node1->next = node2;
  node2->next = node3;
  node3->next = node4;
  node4->next = node5;
  return node1;
}
void Print(ListNode* head) {
  while (head) {
    cout << head->val << " ";
    head = head->next;
  }
  cout << endl;
}
void Test1() {
  ListNode* head = Init();
  Print(head);

  ListNode* node1 = new ListNode(6);
  ListNode* node2 = new ListNode(7);
  ListNode* node3 = new ListNode(8);
  node1->next = node2;
  node2->next = node3;
  // 头插法插入头节点为node1的链表；
  //   ListNode *pre = head, *next;
  //   while (node1) {
  //     next = node1->next;
  //     node1->next = pre->next;
  //     pre->next = node1;
  //     node1 = next;
  //   }
  //   Print(head);

  // 尾插法插入头节点为node1的链表；
  ListNode *cur = head, *next;
  while (cur && cur->next) cur = cur->next;
  while (node1) {
    next = node1->next;
    node1->next = cur->next;
    cur->next = node1;
    cur = node1;
    node1 = next;
  }
  Print(head);
}
int main() {
  Test1();

  return 0;
}
// g++ -o test_linked_list test_linked_list.cc linked_list.cc -std=c++11